﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'table', 'common', 'treeTable', "layer"], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layer=layui.layer,
            treeTable = layui.treeTable,
            common = layui.common;
        //加载数据
        //var loading = layer.load(0, { shade: false });
        var queryJson = '';
        //权限控制(js是值传递)
        currentTableBar.innerHTML = common.authorizeButtonNew(currentTableBar.innerHTML);
        toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
        wcLoading.close();
        var rendertree = common.rendertreetable({
            elem: '#currentTableId',          
            //懒加载设置
            tree: {
                iconIndex: 1,           // 折叠图标显示在第几列
                idName: 'F_Id',  // id字段名称
                arrowType: 'arrow2',
                getIcon: 'ew-tree-icon-style2',
                haveChildName: 'haveChild'  // 自定义标识是否还有子节点的字段名称
            },
            reqData: function (data, callback) {
                var pid = data ? data.F_Id : '0';
                common.ajax({
                    url: "/SystemManage/Area/GetListJson",
                    dataType: "json",
                    //懒加载的查询参数放这里
                    data: { keyValue: pid, keyword: $('#txt_keyword').val() },
                    async: false,
                    success: function (data) {
                        callback(data.data);
                    }
                });
            },
            cols: [[ 
                { type: "radio", width: 50 },
                { field: 'F_FullName', title: '名称', width: 200 },
                { field: 'F_EnCode', title: '编号', width: 150 },
                {
                    field: 'F_EnabledMark', title: '状态', width: 80,
                    templet: function (d) {
                        if (d.F_EnabledMark == true) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>有效</span>";
                        } else {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>无效</span>";
                        }
                    }
                }, 
                {
                    field: 'F_CreatorTime', title: '创建时间', width: 120,
                    templet: function (d) {
                        if (d.F_CreatorTime) {
                            var time = new Date(d.F_CreatorTime);
                            return time.Format("yyyy-MM-dd");
                        }
                        return '';
                    }
                },
                { field: 'F_Description', title: '备注', minWidth: 150 },
                { title: '操作', width: 170, toolbar: '#currentTableBar', align: "center" }
            ]]
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            common.reloadtreetable(rendertree, {}); 
            return false;
        });
        //行点击事件监听，控制按钮显示
        var oneList = ["NF-edit", "NF-details", "NF-delete"];//选择1条显示
        common.treeTableRowClick("radio", rendertree, "currentTableId", oneList);
        /**
         * toolbar监听事件
         */
        treeTable.on('toolbar(currentTableId)', function (obj) {
            var data = rendertree.checkStatus();
            if (obj.event === 'add') {  // 监听操作
                var keyValue = data.length==1 ? data[0].F_Id : null;
                common.modalOpen({
                    title: "添加区域",
                    url: "/SystemManage/Area/Form?event=add&keyValue=" + keyValue,
                    width: "450px",
                    height: "450px",
                });
            }
            else if (obj.event === 'delete') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.deleteForm({
                    url: "/SystemManage/Area/DeleteForm",
                    param: { keyValue: data[0].F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'edit') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "编辑区域",
                    url: "/SystemManage/Area/Form?event=edit&keyValue=" + data[0].F_Id,
                    width: "450px",
                    height: "450px",
                });
            }
            else if (obj.event === 'details') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "查看区域",
                    url: "/SystemManage/Area/Details?keyValue=" + data[0].F_Id,
                    width: "450px",
                    height: "450px",
                    btn:[]
                });
            }
            else if (obj.event === 'TABLE_SEARCH') {
                var _that = $("#searchField");
                if (_that.hasClass("layui-hide")) {
                    _that.removeClass('layui-hide');
                } else {
                    _that.addClass('layui-hide');
                }
            }
            return false;
        });
        //toolbar监听事件
        treeTable.on('tool(currentTableId)', function (obj) {
            if (obj.event === 'delete') {
                common.deleteForm({
                    url: "/SystemManage/Area/DeleteForm",
                    param: { keyValue: obj.data.F_Id },
                    success: function () {
                        obj.del();
                    }
                });
            }
            else if (obj.event === 'edit') {
                common.modalOpen({
                    title: "编辑区域",
                    url: "/SystemManage/Area/Form?event=edit&keyValue=" + obj.data.F_Id,
                    width: "450px",
                    height: "450px",
                });
            }
            else if (obj.event === 'details') {
                common.modalOpen({
                    title: "查看区域",
                    url: "/SystemManage/Area/Details?keyValue=" + obj.data.F_Id,
                    width: "500px",
                    height: "500px",
                    data: obj.data,
                    btn: []
                });
            }
            return false;
        });
    });
</script>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset layui-hide" id="searchField">
            @*<legend>搜索信息</legend>*@
            <div>
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字:</label>
                            <div class="layui-input-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button id="NF-add" name="NF-add" authorize class="layui-btn layui-btn-sm data-add-btn" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                <button id="NF-edit" name="NF-edit" authorize class="layui-btn layui-btn-sm layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                <button id="NF-delete" name="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                <button id="NF-details" name="NF-details" authorize class="layui-btn layui-btn-sm layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a id="NF-edit" authorize class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
            <a id="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"><i class="layui-icon">&#xe640;</i></a>
            <a id="NF-details" authorize class="layui-btn layui-btn-sm layui-btn-normal data-info-btn" lay-event="details"><i class="layui-icon">&#xe60b;</i></a>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>